//    Copyright (C) Kherty.  All rights reserved.
using System;

namespace OpenLS.Spreadsheet.Expressions
{
    abstract class DimensionReference<T, TOther>: Reference where T: Dimension where TOther: Dimension
    {
        public abstract string Label{get;}
        public abstract T Anchor { get;}

        internal bool IsDeleted
        {
            get
            {
                return Anchor.IsDeleted;
            }
        }

        internal abstract DimensionReference<T, TOther> OffsetDim(CellRelativeAddress address);
        internal abstract DimensionReference<TOther, T> SwapDimension();

        internal DimensionReference<TOther, T> Transposed<TT>(Cell target) where TT : Dimension
        {
            var result =  SwapDimension();
            CellRelativeAddress offset;
            if (typeof(T) == typeof(Column))
                offset = new CellRelativeAddress(target.Row.Index - target.Column.Index, 0);
            else
            {
                offset = new CellRelativeAddress(0, target.Column.Index - target.Row.Index);
            }
            result = result.OffsetDim(offset);
            return result;
        }

    }
}
